package cn.zhouchao.org.dto;

import cn.zhouchao.org.domain.Employee;
import cn.zhouchao.org.domain.Shop;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/*
* 店铺入住 参数 dto
* */
@Data
public class ShopSettlementDto { // 前端传给后端的数据 DTO
    // @NotNull 对象或Integer/Long 不为空
    // @NotEmpty   集合 不为空
    @NotBlank(message = "店铺名称不能为空！")
    private String name;
    @NotBlank(message = "店铺电话不能为空！")
    private String tel;
    @NotBlank(message = "店铺地址不能为空！")
    private String address;
    private String logo;
    @Valid
    private EmployeeDto admin;

    public Shop getShop() { // 前端传给后端的数据
        return Shop.builder()
                .name(this.getName())
                .tel(this.getTel())
                .address(this.getAddress())
                .logo(this.getLogo())
                .registerTime(new Date())
                .state(0)
                .build();
    }

    public Employee getEmp() { // 前端传给后端的数据
        Employee employee = new Employee();
        BeanUtils.copyProperties(admin, employee);
        employee.setAge(24);
        employee.setState(1);
        return employee;
    }
}
